home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / comms / non-internet / samba / source / loadparm.c < prev    next >
C/C++ Source or Header  |  1996-06-26  |  62KB  |  1,888 lines

  1. /* 
  2.    Unix SMB/Netbios implementation.
  3.    Version 1.9.
  4.    Parameter loading functions
  5.    Copyright (C) Karl Auer 1993,1994
  6.  
  7.    Largely re-written by Andrew Tridgell, September 1994
  8.    
  9.    This program is free software; you can redistribute it and/or modify
  10.    it under the terms of the GNU General Public License as published by
  11.    the Free Software Foundation; either version 2 of the License, or
  12.    (at your option) any later version.
  13.    
  14.    This program is distributed in the hope that it will be useful,
  15.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.    GNU General Public License for more details.
  18.    
  19.    You should have received a copy of the GNU General Public License
  20.    along with this program; if not, write to the Free Software
  21.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22. */
  23.  
  24. /*
  25.  *  Load parameters.
  26.  *
  27.  *  This module provides suitable callback functions for the params
  28.  *  module. It builds the internal table of service details which is
  29.  *  then used by the rest of the server.
  30.  *
  31.  * To add a parameter:
  32.  *
  33.  * 1) add it to the global or service structure definition
  34.  * 2) add it to the parm_table
  35.  * 3) add it to the list of available functions (eg: using FN_GLOBAL_STRING())
  36.  * 4) If it's a global then initialise it in init_globals. If a local
  37.  *    (ie. service) parameter then initialise it in the sDefault structure
  38.  *  
  39.  *
  40.  * Notes:
  41.  *   The configuration file is processed sequentially for speed. It is NOT
  42.  *   accessed randomly as happens in 'real' Windows. For this reason, there
  43.  *   is a fair bit of sequence-dependent code here - ie., code which assumes
  44.  *   that certain things happen before others. In particular, the code which
  45.  *   happens at the boundary between sections is delicately poised, so be
  46.  *   careful!
  47.  *
  48.  */
  49.  
  50. #include "includes.h"
  51.  
  52. #include "params.h"
  53. #include "loadparm.h"
  54. #include "pcap.h"
  55.  
  56. BOOL bLoaded = False;
  57.  
  58. extern int DEBUGLEVEL;
  59. extern int ReadSize;
  60. extern pstring user_socket_options;
  61. extern pstring smbrun_path;
  62.  
  63. #ifndef GLOBAL_NAME
  64. #define GLOBAL_NAME "global"
  65. #endif
  66.  
  67. #ifndef PRINTCAP_NAME
  68. #ifdef AIX
  69. #define PRINTCAP_NAME "/etc/qconfig"
  70. #else
  71. #define PRINTCAP_NAME "/etc/printcap"
  72. #endif
  73. #endif
  74.  
  75. #ifndef PRINTERS_NAME
  76. #define PRINTERS_NAME "printers"
  77. #endif
  78.  
  79. #ifndef HOMES_NAME
  80. #define HOMES_NAME "homes"
  81. #endif
  82.  
  83. /* some helpful bits */
  84. #define pSERVICE(i) ServicePtrs[i]
  85. #define iSERVICE(i) (*pSERVICE(i))
  86. #define LP_SNUM_OK(iService) (((iService) >= 0) && ((iService) < iNumServices) && iSERVICE(iService).valid)
  87. #define VALID(i) iSERVICE(i).valid
  88.  
  89. /* these are the types of parameter we have */
  90. typedef enum
  91. {
  92.   P_BOOL,P_BOOLREV,P_CHAR,P_INTEGER,P_OCTAL,P_STRING,P_GSTRING
  93. } parm_type;
  94.  
  95. typedef enum
  96. {
  97.   P_LOCAL,P_GLOBAL,P_NONE
  98. } parm_class;
  99.  
  100. int keepalive=0;
  101. extern BOOL use_getwd_cache;
  102.  
  103. extern int extra_time_offset;
  104. #ifdef KANJI
  105. extern int coding_system;
  106. #endif
  107.  
  108. /* 
  109.  * This structure describes global (ie., server-wide) parameters.
  110.  */
  111. typedef struct
  112. {
  113.    char *szPrintcapname;
  114.    char *szLockDir;
  115.    char *szRootdir;
  116.    char *szDefaultService;
  117.    char *szDfree;
  118.    char *szMsgCommand;
  119.    char *szHostsEquiv;
  120.    char *szServerString;
  121.    char *szAutoServices;
  122.    char *szPasswdProgram;
  123.    char *szPasswdChat;
  124.    char *szLogFile;
  125.    char *szConfigFile;
  126.    char *szSMBPasswdFile;
  127.    char *szPasswordServer;
  128.    char *szSocketOptions;
  129.    char *szValidChars;
  130.    char *szWorkGroup;
  131.    char *szDomainController;
  132.    char *szUsernameMap;
  133.    char *szCharacterSet;
  134.    char *szLogonScript;
  135.    int max_log_size;
  136.    int mangled_stack;
  137.    int max_xmit;
  138.    int max_mux;
  139.    int max_packet;
  140.    int pwordlevel;
  141.    int deadtime;
  142.    int maxprotocol;
  143.    int security;
  144.    int printing;
  145.    int maxdisksize;
  146.    int lpqcachetime;
  147.    int syslog;
  148.    int os_level;
  149.    int max_ttl;
  150.    BOOL bPreferredMaster;
  151.    BOOL bDomainMaster;
  152.    BOOL bDomainLogons;
  153.    BOOL bEncryptPasswords;
  154.    BOOL bStripDot;
  155.    BOOL bNullPasswords;
  156.    BOOL bLoadPrinters;
  157.    BOOL bUseRhosts;
  158.    BOOL bReadRaw;
  159.    BOOL bWriteRaw;
  160.    BOOL bReadPrediction;
  161.    BOOL bReadbmpx;
  162.    BOOL bSyslogOnly;
  163.    BOOL bBrowseList;
  164. } global;
  165.  
  166. static global Globals;
  167.  
  168.  
  169.  
  170. /* 
  171.  * This structure describes a single service. 
  172.  */
  173. typedef struct
  174. {
  175.   BOOL valid;
  176.   char *szService;
  177.   char *szPath;
  178.   char *szUsername;
  179.   char *szGuestaccount;
  180.   char *szInvalidUsers;
  181.   char *szValidUsers;
  182.   char *szAdminUsers;
  183.   char *szCopy;
  184.   char *szInclude;
  185.   char *szPreExec;
  186.   char *szPostExec;
  187.   char *szRootPreExec;
  188.   char *szRootPostExec;
  189.   char *szPrintcommand;
  190.   char *szLpqcommand;
  191.   char *szLprmcommand;
  192.   char *szLppausecommand;
  193.   char *szLpresumecommand;
  194.   char *szPrintername;
  195.   char *szDontdescend;
  196.   char *szHostsallow;
  197.   char *szHostsdeny;
  198.   char *szMagicScript;
  199.   char *szMagicOutput;
  200.   char *szMangledMap;
  201.   char *comment;
  202.   char *force_user;
  203.   char *force_group;
  204.   char *readlist;
  205.   char *writelist;
  206.   char *volume;
  207.   int  iMinPrintSpace;
  208.   int  iCreate_mode;
  209.   int  iMaxConnections;
  210.   int  iDefaultCase;
  211.   BOOL bAlternatePerm;
  212.   BOOL bRevalidate;
  213.   BOOL bCaseSensitive;
  214.   BOOL bCasePreserve;
  215.   BOOL bShortCasePreserve;
  216.   BOOL bCaseMangle;
  217.   BOOL status;
  218.   BOOL bHideDotFiles;
  219.   BOOL bBrowseable;
  220.   BOOL bAvailable;
  221.   BOOL bRead_only;
  222.   BOOL bNo_set_dir;
  223.   BOOL bGuest_only;
  224.   BOOL bGuest_ok;
  225.   BOOL bPrint_ok;
  226.   BOOL bPostscript;
  227.   BOOL bMap_system;
  228.   BOOL bMap_hidden;
  229.   BOOL bMap_archive;
  230.   BOOL bLocking;
  231.   BOOL bStrictLocking;
  232.   BOOL bShareModes;
  233.   BOOL bOnlyUser;
  234.   BOOL bMangledNames;
  235.   BOOL bWidelinks;
  236.   BOOL bSyncAlways;
  237.   char magic_char;
  238.   BOOL *copymap;
  239.   char dummy[3]; /* for alignment */
  240. } service;
  241.  
  242.  
  243. /* This is a default service used to prime a services structure */
  244. static service sDefault = 
  245. {
  246.   True,   /* valid */
  247.   NULL,    /* szService */
  248.   NULL,    /* szPath */
  249.   NULL,    /* szUsername */
  250.   NULL,    /* szGuestAccount */
  251.   NULL,    /* szInvalidUsers */
  252.   NULL,    /* szValidUsers */
  253.   NULL,    /* szAdminUsers */
  254.   NULL,    /* szCopy */
  255.   NULL,    /* szInclude */
  256.   NULL,    /* szPreExec */
  257.   NULL,    /* szPostExec */
  258.   NULL,    /* szRootPreExec */
  259.   NULL,    /* szRootPostExec */
  260.   NULL,    /* szPrintcommand */
  261.   NULL,    /* szLpqcommand */
  262.   NULL,    /* szLprmcommand */
  263.   NULL,    /* szLppausecommand */
  264.   NULL,    /* szLpresumecommand */
  265.   NULL,    /* szPrintername */
  266.   NULL,    /* szDontdescend */
  267.   NULL,    /* szHostsallow */
  268.   NULL,    /* szHostsdeny */
  269.   NULL,    /* szMagicScript */
  270.   NULL,    /* szMagicOutput */
  271.   NULL,    /* szMangledMap */
  272.   NULL,    /* comment */
  273.   NULL,    /* force user */
  274.   NULL,    /* force group */
  275.   NULL,    /* readlist */
  276.   NULL,    /* writelist */
  277.   NULL,    /* volume */
  278.   0,       /* iMinPrintSpace */
  279.   0755,    /* iCreate_mode */
  280.   0,       /* iMaxConnections */
  281.   CASE_LOWER, /* iDefaultCase */
  282.   False,   /* bAlternatePerm */
  283.   False,   /* revalidate */
  284.   False,   /* case sensitive */
  285.   False,   /* case preserve */
  286.   False,   /* short case preserve */
  287.   False,  /* case mangle */
  288.   True,  /* status */
  289.   True,  /* bHideDotFiles */
  290.   True,  /* bBrowseable */
  291.   True,  /* bAvailable */
  292.   True,  /* bRead_only */
  293.   True,  /* bNo_set_dir */
  294.   False, /* bGuest_only */
  295.   False, /* bGuest_ok */
  296.   False, /* bPrint_ok */
  297.   False, /* bPostscript */
  298.   False, /* bMap_system */
  299.   False, /* bMap_hidden */
  300.   True,  /* bMap_archive */
  301.   True,  /* bLocking */
  302.   False,  /* bStrictLocking */
  303.   True,  /* bShareModes */
  304.   False, /* bOnlyUser */
  305.   True,  /* bMangledNames */
  306.   True,  /* bWidelinks */
  307.   False, /* bSyncAlways */
  308.   '~',   /* magic char */
  309.   NULL,  /* copymap */
  310.   ""     /* dummy */
  311. };
  312.  
  313.  
  314.  
  315. /* local variables */
  316. static service **ServicePtrs = NULL;
  317. static int iNumServices = 0;
  318. static int iServiceIndex = 0;
  319. static BOOL bInGlobalSection = True;
  320. static BOOL bGlobalOnly = False;
  321.  
  322.  
  323. #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
  324.  
  325. /* prototypes for the special type handlers */
  326. static BOOL handle_valid_chars(char *pszParmValue, char **ptr);
  327. static BOOL handle_include(char *pszParmValue, char **ptr);
  328. static BOOL handle_copy(char *pszParmValue, char **ptr);
  329. static BOOL handle_protocol(char *pszParmValue,int *val);
  330. static BOOL handle_security(char *pszParmValue,int *val);
  331. static BOOL handle_case(char *pszParmValue,int *val);
  332. static BOOL handle_printing(char *pszParmValue,int *val);
  333. static BOOL handle_character_set(char *pszParmValue,int *val);
  334. #ifdef KANJI
  335. static BOOL handle_coding_system(char *pszParmValue,int *val);
  336. #endif /* KANJI */
  337.  
  338. struct parm_struct
  339. {
  340.   char *label;
  341.   parm_type type;
  342.   parm_class class;
  343.   void *ptr;
  344.   BOOL (*special)();
  345. } parm_table[] =
  346. {
  347.   {"debuglevel",       P_INTEGER, P_GLOBAL, &DEBUGLEVEL,                NULL},
  348.   {"log level",        P_INTEGER, P_GLOBAL, &DEBUGLEVEL,                NULL},
  349.   {"syslog",           P_INTEGER, P_GLOBAL, &Globals.syslog,            NULL},
  350.   {"syslog only",      P_BOOL,    P_GLOBAL, &Globals.bSyslogOnly,       NULL},
  351.   {"protocol",         P_INTEGER, P_GLOBAL, &Globals.maxprotocol,handle_protocol},
  352.   {"security",         P_INTEGER, P_GLOBAL, &Globals.security,handle_security},
  353.   {"printing",         P_INTEGER, P_GLOBAL, &Globals.printing,handle_printing},
  354.   {"max disk size",    P_INTEGER, P_GLOBAL, &Globals.maxdisksize,       NULL},
  355.   {"lpq cache time",   P_INTEGER, P_GLOBAL, &Globals.lpqcachetime,      NULL},
  356.   {"encrypt passwords",P_BOOL,    P_GLOBAL, &Globals.bEncryptPasswords, NULL},
  357.   {"getwd cache",      P_BOOL,    P_GLOBAL, &use_getwd_cache,           NULL},
  358.   {"read prediction",  P_BOOL,    P_GLOBAL, &Globals.bReadPrediction,   NULL},
  359.   {"read bmpx",        P_BOOL,    P_GLOBAL, &Globals.bReadbmpx,         NULL},
  360.   {"read raw",         P_BOOL,    P_GLOBAL, &Globals.bReadRaw,          NULL},
  361.   {"write raw",        P_BOOL,    P_GLOBAL, &Globals.bWriteRaw,         NULL},
  362.   {"use rhosts",       P_BOOL,    P_GLOBAL, &Globals.bUseRhosts,        NULL},
  363.   {"load printers",    P_BOOL,    P_GLOBAL, &Globals.bLoadPrinters,     NULL},
  364.   {"null passwords",   P_BOOL,    P_GLOBAL, &Globals.bNullPasswords,    NULL},
  365.   {"strip dot",        P_BOOL,    P_GLOBAL, &Globals.bStripDot,         NULL},
  366.   {"password server",  P_STRING,  P_GLOBAL, &Globals.szPasswordServer,  NULL},
  367.   {"socket options",   P_GSTRING, P_GLOBAL, user_socket_options,        NULL},
  368.   {"smbrun",           P_GSTRING, P_GLOBAL, smbrun_path,                NULL},
  369.   {"log file",         P_STRING,  P_GLOBAL, &Globals.szLogFile,         NULL},
  370.   {"config file",      P_STRING,  P_GLOBAL, &Globals.szConfigFile,      NULL},
  371.   {"smb passwd file",  P_STRING,  P_GLOBAL, &Globals.szSMBPasswdFile,   NULL},
  372.   {"hosts equiv",      P_STRING,  P_GLOBAL, &Globals.szHostsEquiv,      NULL},
  373.   {"preload",          P_STRING,  P_GLOBAL, &Globals.szAutoServices,    NULL},
  374.   {"auto services",    P_STRING,  P_GLOBAL, &Globals.szAutoServices,    NULL},
  375.   {"server string",    P_STRING,  P_GLOBAL, &Globals.szServerString,    NULL},
  376.   {"printcap name",    P_STRING,  P_GLOBAL, &Globals.szPrintcapname,    NULL},
  377.   {"printcap",         P_STRING,  P_GLOBAL, &Globals.szPrintcapname,    NULL},
  378.   {"lock dir",         P_STRING,  P_GLOBAL, &Globals.szLockDir,         NULL},
  379.   {"lock directory",   P_STRING,  P_GLOBAL, &Globals.szLockDir,         NULL},
  380.   {"root directory",   P_STRING,  P_GLOBAL, &Globals.szRootdir,         NULL},
  381.   {"root dir",         P_STRING,  P_GLOBAL, &Globals.szRootdir,         NULL},
  382.   {"root",             P_STRING,  P_GLOBAL, &Globals.szRootdir,         NULL},
  383.   {"default service",  P_STRING,  P_GLOBAL, &Globals.szDefaultService,  NULL},
  384.   {"default",          P_STRING,  P_GLOBAL, &Globals.szDefaultService,  NULL},
  385.   {"message command",  P_STRING,  P_GLOBAL, &Globals.szMsgCommand,      NULL},
  386.   {"dfree command",    P_STRING,  P_GLOBAL, &Globals.szDfree,           NULL},
  387.   {"passwd program",   P_STRING,  P_GLOBAL, &Globals.szPasswdProgram,   NULL},
  388.   {"passwd chat",      P_STRING,  P_GLOBAL, &Globals.szPasswdChat,      NULL},
  389.   {"valid chars",      P_STRING,  P_GLOBAL, &Globals.szValidChars,      handle_valid_chars},
  390.   {"workgroup",        P_STRING,  P_GLOBAL, &Globals.szWorkGroup,       NULL},
  391.   {"domain controller",P_STRING,  P_GLOBAL, &Globals.szDomainController,NULL},
  392.   {"username map",     P_STRING,  P_GLOBAL, &Globals.szUsernameMap,     NULL},
  393.   {"character set",    P_STRING,  P_GLOBAL, &Globals.szCharacterSet,    handle_character_set},
  394.   {"logon script",     P_STRING,  P_GLOBAL, &Globals.szLogonScript,     NULL},
  395.   {"max log size",     P_INTEGER, P_GLOBAL, &Globals.max_log_size,      NULL},
  396.   {"mangled stack",    P_INTEGER, P_GLOBAL, &Globals.mangled_stack,     NULL},
  397.   {"max mux",          P_INTEGER, P_GLOBAL, &Globals.max_mux,           NULL},
  398.   {"max xmit",         P_INTEGER, P_GLOBAL, &Globals.max_xmit,          NULL},
  399.   {"max packet",       P_INTEGER, P_GLOBAL, &Globals.max_packet,        NULL},
  400.   {"packet size",      P_INTEGER, P_GLOBAL, &Globals.max_packet,        NULL},
  401.   {"password level",   P_INTEGER, P_GLOBAL, &Globals.pwordlevel,        NULL},
  402.   {"keepalive",        P_INTEGER, P_GLOBAL, &keepalive,                 NULL},
  403.   {"deadtime",         P_INTEGER, P_GLOBAL, &Globals.deadtime,          NULL},
  404.   {"time offset",      P_INTEGER, P_GLOBAL, &extra_time_offset,         NULL},
  405.   {"read size",        P_INTEGER, P_GLOBAL, &ReadSize,                  NULL},
  406. #ifdef KANJI
  407.   {"coding system",    P_INTEGER, P_GLOBAL, &coding_system, handle_coding_system},
  408. #endif /* KANJI */
  409.   {"os level",         P_INTEGER, P_GLOBAL, &Globals.os_level,          NULL},
  410.   {"max ttl",          P_INTEGER, P_GLOBAL, &Globals.max_ttl,           NULL},
  411.   {"preferred master", P_BOOL,    P_GLOBAL, &Globals.bPreferredMaster,  NULL},
  412.   {"prefered master",  P_BOOL,    P_GLOBAL, &Globals.bPreferredMaster,  NULL},
  413.   {"domain master",    P_BOOL,    P_GLOBAL, &Globals.bDomainMaster,     NULL},
  414.   {"domain logons",    P_BOOL,    P_GLOBAL, &Globals.bDomainLogons,     NULL},
  415.   {"browse list",      P_BOOL,    P_GLOBAL, &Globals.bBrowseList,       NULL},
  416.  
  417.   {"-valid",           P_BOOL,    P_LOCAL,  &sDefault.valid,            NULL},
  418.   {"comment",          P_STRING,  P_LOCAL,  &sDefault.comment,          NULL},
  419.   {"copy",             P_STRING,  P_LOCAL,  &sDefault.szCopy,    handle_copy},
  420.   {"include",          P_STRING,  P_LOCAL,  &sDefault.szInclude, handle_include},
  421.   {"exec",             P_STRING,  P_LOCAL,  &sDefault.szPreExec,        NULL},
  422.   {"preexec",          P_STRING,  P_LOCAL,  &sDefault.szPreExec,        NULL},
  423.   {"postexec",         P_STRING,  P_LOCAL,  &sDefault.szPostExec,       NULL},
  424.   {"root preexec",     P_STRING,  P_LOCAL,  &sDefault.szRootPreExec,    NULL},
  425.   {"root postexec",    P_STRING,  P_LOCAL,  &sDefault.szRootPostExec,   NULL},
  426.   {"alternate permissions",P_BOOL,P_LOCAL,  &sDefault.bAlternatePerm,   NULL},
  427.   {"revalidate",       P_BOOL,    P_LOCAL,  &sDefault.bRevalidate,      NULL},
  428.   {"default case",     P_INTEGER, P_LOCAL,  &sDefault.iDefaultCase,   handle_case},
  429.   {"case sensitive",   P_BOOL,    P_LOCAL,  &sDefault.bCaseSensitive,   NULL},
  430.   {"casesignames",     P_BOOL,    P_LOCAL,  &sDefault.bCaseSensitive,   NULL},
  431.   {"preserve case",    P_BOOL,    P_LOCAL,  &sDefault.bCasePreserve,    NULL},
  432.   {"short preserve case",P_BOOL,  P_LOCAL,  &sDefault.bShortCasePreserve,NULL},
  433.   {"mangle case",      P_BOOL,    P_LOCAL,  &sDefault.bCaseMangle,      NULL},
  434.   {"mangling char",    P_CHAR,    P_LOCAL,  &sDefault.magic_char,       NULL},
  435.   {"browseable",       P_BOOL,    P_LOCAL,  &sDefault.bBrowseable,      NULL},
  436.   {"browsable",        P_BOOL,    P_LOCAL,  &sDefault.bBrowseable,      NULL},
  437.   {"available",        P_BOOL,    P_LOCAL,  &sDefault.bAvailable,       NULL},
  438.   {"path",             P_STRING,  P_LOCAL,  &sDefault.szPath,           NULL},
  439.   {"directory",        P_STRING,  P_LOCAL,  &sDefault.szPath,           NULL},
  440.   {"username",         P_STRING,  P_LOCAL,  &sDefault.szUsername,       NULL},
  441.   {"user",             P_STRING,  P_LOCAL,  &sDefault.szUsername,       NULL},
  442.   {"users",            P_STRING,  P_LOCAL,  &sDefault.szUsername,       NULL},
  443.   {"guest account",    P_STRING,  P_LOCAL,  &sDefault.szGuestaccount,   NULL},
  444.   {"invalid users",    P_STRING,  P_LOCAL,  &sDefault.szInvalidUsers,   NULL},
  445.   {"valid users",      P_STRING,  P_LOCAL,  &sDefault.szValidUsers,     NULL},
  446.   {"admin users",      P_STRING,  P_LOCAL,  &sDefault.szAdminUsers,     NULL},
  447.   {"read list",        P_STRING,  P_LOCAL,  &sDefault.readlist,         NULL},
  448.   {"write list",       P_STRING,  P_LOCAL,  &sDefault.writelist,        NULL},
  449.   {"volume",           P_STRING,  P_LOCAL,  &sDefault.volume,           NULL},
  450.   {"force user",       P_STRING,  P_LOCAL,  &sDefault.force_user,       NULL},
  451.   {"force group",      P_STRING,  P_LOCAL,  &sDefault.force_group,      NULL},
  452.   {"group",            P_STRING,  P_LOCAL,  &sDefault.force_group,      NULL},
  453.   {"read only",        P_BOOL,    P_LOCAL,  &sDefault.bRead_only,       NULL},
  454.   {"write ok",         P_BOOLREV, P_LOCAL,  &sDefault.bRead_only,       NULL},
  455.   {"writeable",        P_BOOLREV, P_LOCAL,  &sDefault.bRead_only,       NULL},
  456.   {"writable",         P_BOOLREV, P_LOCAL,  &sDefault.bRead_only,       NULL},
  457.   {"max connections",  P_INTEGER, P_LOCAL,  &sDefault.iMaxConnections,  NULL},
  458.   {"min print space",  P_INTEGER, P_LOCAL,  &sDefault.iMinPrintSpace,   NULL},
  459.   {"create mask",      P_OCTAL,   P_LOCAL,  &sDefault.iCreate_mode,     NULL},
  460.   {"create mode",      P_OCTAL,   P_LOCAL,  &sDefault.iCreate_mode,     NULL},
  461.   {"set directory",    P_BOOLREV, P_LOCAL,  &sDefault.bNo_set_dir,      NULL},
  462.   {"status",           P_BOOL,    P_LOCAL,  &sDefault.status,           NULL},
  463.   {"hide dot files",   P_BOOL,    P_LOCAL,  &sDefault.bHideDotFiles,    NULL},
  464.   {"guest only",       P_BOOL,    P_LOCAL,  &sDefault.bGuest_only,      NULL},
  465.   {"only guest",       P_BOOL,    P_LOCAL,  &sDefault.bGuest_only,      NULL},
  466.   {"guest ok",         P_BOOL,    P_LOCAL,  &sDefault.bGuest_ok,        NULL},
  467.   {"public",           P_BOOL,    P_LOCAL,  &sDefault.bGuest_ok,        NULL},
  468.   {"print ok",         P_BOOL,    P_LOCAL,  &sDefault.bPrint_ok,        NULL},
  469.   {"printable",        P_BOOL,    P_LOCAL,  &sDefault.bPrint_ok,        NULL},
  470.   {"postscript",       P_BOOL,    P_LOCAL,  &sDefault.bPostscript,      NULL},
  471.   {"map system",       P_BOOL,    P_LOCAL,  &sDefault.bMap_system,      NULL},
  472.   {"map hidden",       P_BOOL,    P_LOCAL,  &sDefault.bMap_hidden,      NULL},
  473.   {"map archive",      P_BOOL,    P_LOCAL,  &sDefault.bMap_archive,     NULL},
  474.   {"locking",          P_BOOL,    P_LOCAL,  &sDefault.bLocking,         NULL},
  475.   {"strict locking",   P_BOOL,    P_LOCAL,  &sDefault.bStrictLocking,   NULL},
  476.   {"share modes",      P_BOOL,    P_LOCAL,  &sDefault.bShareModes,      NULL},
  477.   {"only user",        P_BOOL,    P_LOCAL,  &sDefault.bOnlyUser,        NULL},
  478.   {"wide links",       P_BOOL,    P_LOCAL,  &sDefault.bWidelinks,       NULL},
  479.   {"sync always",      P_BOOL,    P_LOCAL,  &sDefault.bSyncAlways,      NULL},
  480.   {"mangled names",    P_BOOL,    P_LOCAL,  &sDefault.bMangledNames,    NULL},
  481.   {"print command",    P_STRING,  P_LOCAL,  &sDefault.szPrintcommand,   NULL},
  482.   {"lpq command",      P_STRING,  P_LOCAL,  &sDefault.szLpqcommand,     NULL},
  483.   {"lprm command",     P_STRING,  P_LOCAL,  &sDefault.szLprmcommand,    NULL},
  484.   {"lppause command",  P_STRING,  P_LOCAL,  &sDefault.szLppausecommand, NULL},
  485.   {"lpresume command", P_STRING,  P_LOCAL,  &sDefault.szLpresumecommand,NULL},
  486.   {"printer",          P_STRING,  P_LOCAL,  &sDefault.szPrintername,    NULL},
  487.   {"printer name",     P_STRING,  P_LOCAL,  &sDefault.szPrintername,    NULL},
  488.   {"hosts allow",      P_STRING,  P_LOCAL,  &sDefault.szHostsallow,     NULL},
  489.   {"allow hosts",      P_STRING,  P_LOCAL,  &sDefault.szHostsallow,     NULL},
  490.   {"hosts deny",       P_STRING,  P_LOCAL,  &sDefault.szHostsdeny,      NULL},
  491.   {"deny hosts",       P_STRING,  P_LOCAL,  &sDefault.szHostsdeny,      NULL},
  492.   {"dont descend",     P_STRING,  P_LOCAL,  &sDefault.szDontdescend,    NULL},
  493.   {"magic script",     P_STRING,  P_LOCAL,  &sDefault.szMagicScript,    NULL},
  494.   {"magic output",     P_STRING,  P_LOCAL,  &sDefault.szMagicOutput,    NULL},
  495.   {"mangled map",      P_STRING,  P_LOCAL,  &sDefault.szMangledMap,     NULL},
  496.  
  497.   {NULL,               P_BOOL,    P_NONE,   NULL,                       NULL}
  498. };
  499.  
  500.  
  501.  
  502. /***************************************************************************
  503. Initialise the global parameter structure.
  504. ***************************************************************************/
  505. static void init_globals(void)
  506. {
  507.   static BOOL done_init = False;
  508.   pstring s;
  509.  
  510.   if (!done_init)
  511.     {
  512.       int i;
  513.       bzero((void *)&Globals,sizeof(Globals));
  514.  
  515.       for (i = 0; parm_table[i].label; i++) 
  516.     if (parm_table[i].type == P_STRING && 
  517.         parm_table[i].ptr)
  518.       string_init(parm_table[i].ptr,"");
  519.  
  520.       string_set(&sDefault.szGuestaccount, GUEST_ACCOUNT);
  521.  
  522.       done_init = True;
  523.     }
  524.  
  525.  
  526.   DEBUG(3,("Initialising global parameters\n"));
  527.  
  528. #ifdef SMB_PASSWD_FILE
  529.   string_set(&Globals.szSMBPasswdFile, SMB_PASSWD_FILE);
  530. #endif
  531.   string_set(&Globals.szPasswdChat,"*old*password* %o\\n *new*password* %n\\n *new*password* %n\\n *changed*");
  532.   string_set(&Globals.szWorkGroup, WORKGROUP);
  533. #ifdef SMB_PASSWD
  534.   string_set(&Globals.szPasswdProgram, SMB_PASSWD);
  535. #else
  536.   string_set(&Globals.szPasswdProgram, "/bin/passwd");
  537. #endif
  538.   string_set(&Globals.szPrintcapname, PRINTCAP_NAME);
  539.   string_set(&Globals.szLockDir, LOCKDIR);
  540.   string_set(&Globals.szRootdir, "/");
  541.   sprintf(s,"Samba %s",VERSION);
  542.   string_set(&Globals.szServerString,s);
  543.   Globals.bLoadPrinters = True;
  544.   Globals.bUseRhosts = False;
  545.   Globals.max_packet = 65535;
  546.   Globals.mangled_stack = 50;
  547.   Globals.max_xmit = Globals.max_packet;
  548.   Globals.max_mux = 2;
  549.   Globals.lpqcachetime = 10;
  550.   Globals.pwordlevel = 0;
  551.   Globals.deadtime = 0;
  552.   Globals.max_log_size = 5000;
  553.   Globals.maxprotocol = PROTOCOL_NT1;
  554.   Globals.security = SEC_SHARE;
  555.   Globals.bEncryptPasswords = False;
  556.   Globals.printing = DEFAULT_PRINTING;
  557.   Globals.bReadRaw = True;
  558.   Globals.bWriteRaw = True;
  559.   Globals.bReadPrediction = False;
  560.   Globals.bReadbmpx = True;
  561.   Globals.bNullPasswords = False;
  562.   Globals.bStripDot = False;
  563.   Globals.syslog = 1;
  564.   Globals.bSyslogOnly = False;
  565.   Globals.os_level = 0;
  566.   Globals.max_ttl = 60*60*4; /* 2 hours default */
  567.   Globals.bPreferredMaster = True;
  568.   Globals.bDomainMaster = False;
  569.   Globals.bDomainLogons = False;
  570.   Globals.bBrowseList = True;
  571.  
  572. #ifdef KANJI
  573.   coding_system = interpret_coding_system (KANJI, SJIS_CODE);
  574. #endif /* KANJI */
  575.  
  576. }
  577.  
  578. /***************************************************************************
  579. check if a string is initialised and if not then initialise it
  580. ***************************************************************************/
  581. static void string_initial(char **s,char *v)
  582. {
  583.   if (!*s || !**s)
  584.     string_init(s,v);
  585. }
  586.  
  587.  
  588. /***************************************************************************
  589. Initialise the sDefault parameter structure.
  590. ***************************************************************************/
  591. static void init_locals(void)
  592. {
  593.   /* choose defaults depending on the type of printing */
  594.   switch (Globals.printing)
  595.     {
  596.     case PRINT_BSD:
  597.     case PRINT_AIX:
  598.       string_initial(&sDefault.szLpqcommand,"lpq -P%p");
  599.       string_initial(&sDefault.szLprmcommand,"lprm -P%p %j");
  600.       string_initial(&sDefault.szPrintcommand,"lpr -r -P%p %s");
  601.       break;
  602.  
  603.     case PRINT_SYSV:
  604.     case PRINT_HPUX:
  605.       string_initial(&sDefault.szLpqcommand,"lpstat -o%p");
  606.       string_initial(&sDefault.szLprmcommand,"cancel %p-%j");
  607.       string_initial(&sDefault.szPrintcommand,"lp -c -d%p %s; rm %s");
  608.       break;
  609.  
  610.     case PRINT_QNX:
  611.       string_initial(&sDefault.szLpqcommand,"lpq -P%p");
  612.       string_initial(&sDefault.szLprmcommand,"lprm -P%p %j");
  613.       string_initial(&sDefault.szPrintcommand,"lp -r -P%p %s");
  614.       break;
  615.  
  616.       
  617.     }
  618. }
  619.  
  620.  
  621. /*******************************************************************
  622. a convenience rooutine to grab string parameters into a rotating
  623. static buffer, and run standard_sub_basic on them. The buffers
  624. can be written to by callers
  625. ********************************************************************/
  626. char *lp_string(char *s)
  627. {
  628.   static pstring bufs[10];
  629.   static int next=0;
  630.   char *ret;
  631.   
  632.   ret = &bufs[next][0];
  633.   next = (next+1)%10;
  634.  
  635.   if (!s) 
  636.     *ret = 0;
  637.   else
  638.     StrnCpy(ret,s,sizeof(pstring)-1);
  639.  
  640.   standard_sub_basic(ret);
  641.   return(ret);
  642. }
  643.  
  644.  
  645. /*
  646.    In this section all the functions that are used to access the 
  647.    parameters from the rest of the program are defined 
  648. */
  649.  
  650. #define FN_GLOBAL_STRING(fn_name,ptr) \
  651.  char *fn_name(void) {return(lp_string(*(char **)(ptr) ? *(char **)(ptr) : ""));}
  652. #define FN_GLOBAL_BOOL(fn_name,ptr) \
  653.  BOOL fn_name(void) {return(*(BOOL *)(ptr));}
  654. #define FN_GLOBAL_CHAR(fn_name,ptr) \
  655.  char fn_name(void) {return(*(char *)(ptr));}
  656. #define FN_GLOBAL_INTEGER(fn_name,ptr) \
  657.  int fn_name(void) {return(*(int *)(ptr));}
  658.  
  659. #define FN_LOCAL_STRING(fn_name,val) \
  660.  char *fn_name(int i) {return(lp_string((LP_SNUM_OK(i)&&pSERVICE(i)->val)?pSERVICE(i)->val : sDefault.val));}
  661. #define FN_LOCAL_BOOL(fn_name,val) \
  662.  BOOL fn_name(int i) {return(LP_SNUM_OK(i)? pSERVICE(i)->val : sDefault.val);}
  663. #define FN_LOCAL_CHAR(fn_name,val) \
  664.  char fn_name(int i) {return(LP_SNUM_OK(i)? pSERVICE(i)->val : sDefault.val);}
  665. #define FN_LOCAL_INTEGER(fn_name,val) \
  666.  int fn_name(int i) {return(LP_SNUM_OK(i)? pSERVICE(i)->val : sDefault.val);}
  667.  
  668. FN_GLOBAL_STRING(lp_logfile,&Globals.szLogFile)
  669. FN_GLOBAL_STRING(lp_configfile,&Globals.szConfigFile)
  670. FN_GLOBAL_STRING(lp_smb_passwd_file,&Globals.szSMBPasswdFile)
  671. FN_GLOBAL_STRING(lp_serverstring,&Globals.szServerString)
  672. FN_GLOBAL_STRING(lp_printcapname,&Globals.szPrintcapname)
  673. FN_GLOBAL_STRING(lp_lockdir,&Globals.szLockDir)
  674. FN_GLOBAL_STRING(lp_rootdir,&Globals.szRootdir)
  675. FN_GLOBAL_STRING(lp_defaultservice,&Globals.szDefaultService)
  676. FN_GLOBAL_STRING(lp_msg_command,&Globals.szMsgCommand)
  677. FN_GLOBAL_STRING(lp_dfree_command,&Globals.szDfree)
  678. FN_GLOBAL_STRING(lp_hosts_equiv,&Globals.szHostsEquiv)
  679. FN_GLOBAL_STRING(lp_auto_services,&Globals.szAutoServices)
  680. FN_GLOBAL_STRING(lp_passwd_program,&Globals.szPasswdProgram)
  681. FN_GLOBAL_STRING(lp_passwd_chat,&Globals.szPasswdChat)
  682. FN_GLOBAL_STRING(lp_passwordserver,&Globals.szPasswordServer)
  683. FN_GLOBAL_STRING(lp_workgroup,&Globals.szWorkGroup)
  684. FN_GLOBAL_STRING(lp_domain_controller,&Globals.szDomainController)
  685. FN_GLOBAL_STRING(lp_username_map,&Globals.szUsernameMap)
  686. FN_GLOBAL_STRING(lp_character_set,&Globals.szCharacterSet) 
  687. FN_GLOBAL_STRING(lp_logon_script,&Globals.szLogonScript) 
  688.  
  689. FN_GLOBAL_BOOL(lp_domain_master,&Globals.bDomainMaster)
  690. FN_GLOBAL_BOOL(lp_domain_logons,&Globals.bDomainLogons)
  691. FN_GLOBAL_BOOL(lp_preferred_master,&Globals.bPreferredMaster)
  692. FN_GLOBAL_BOOL(lp_load_printers,&Globals.bLoadPrinters)
  693. FN_GLOBAL_BOOL(lp_use_rhosts,&Globals.bUseRhosts)
  694. FN_GLOBAL_BOOL(lp_getwdcache,&use_getwd_cache)
  695. FN_GLOBAL_BOOL(lp_readprediction,&Globals.bReadPrediction)
  696. FN_GLOBAL_BOOL(lp_readbmpx,&Globals.bReadbmpx)
  697. FN_GLOBAL_BOOL(lp_readraw,&Globals.bReadRaw)
  698. FN_GLOBAL_BOOL(lp_writeraw,&Globals.bWriteRaw)
  699. FN_GLOBAL_BOOL(lp_null_passwords,&Globals.bNullPasswords)
  700. FN_GLOBAL_BOOL(lp_strip_dot,&Globals.bStripDot)
  701. FN_GLOBAL_BOOL(lp_encrypted_passwords,&Globals.bEncryptPasswords)
  702. FN_GLOBAL_BOOL(lp_syslog_only,&Globals.bSyslogOnly)
  703. FN_GLOBAL_BOOL(lp_browse_list,&Globals.bBrowseList)
  704.  
  705. FN_GLOBAL_INTEGER(lp_os_level,&Globals.os_level)
  706. FN_GLOBAL_INTEGER(lp_max_ttl,&Globals.max_ttl)
  707. FN_GLOBAL_INTEGER(lp_max_log_size,&Globals.max_log_size)
  708. FN_GLOBAL_INTEGER(lp_mangledstack,&Globals.mangled_stack)
  709. FN_GLOBAL_INTEGER(lp_maxxmit,&Globals.max_xmit)
  710. FN_GLOBAL_INTEGER(lp_maxmux,&Globals.max_mux)
  711. FN_GLOBAL_INTEGER(lp_maxpacket,&Globals.max_packet)
  712. FN_GLOBAL_INTEGER(lp_keepalive,&keepalive)
  713. FN_GLOBAL_INTEGER(lp_passwordlevel,&Globals.pwordlevel)
  714. FN_GLOBAL_INTEGER(lp_deadtime,&Globals.deadtime)
  715. FN_GLOBAL_INTEGER(lp_maxprotocol,&Globals.maxprotocol)
  716. FN_GLOBAL_INTEGER(lp_security,&Globals.security)
  717. FN_GLOBAL_INTEGER(lp_printing,&Globals.printing)
  718. FN_GLOBAL_INTEGER(lp_maxdisksize,&Globals.maxdisksize)
  719. FN_GLOBAL_INTEGER(lp_lpqcachetime,&Globals.lpqcachetime)
  720. FN_GLOBAL_INTEGER(lp_syslog,&Globals.syslog)
  721.  
  722. FN_LOCAL_STRING(lp_preexec,szPreExec)
  723. FN_LOCAL_STRING(lp_postexec,szPostExec)
  724. FN_LOCAL_STRING(lp_rootpreexec,szRootPreExec)
  725. FN_LOCAL_STRING(lp_rootpostexec,szRootPostExec)
  726. FN_LOCAL_STRING(lp_servicename,szService)
  727. FN_LOCAL_STRING(lp_pathname,szPath)
  728. FN_LOCAL_STRING(lp_dontdescend,szDontdescend)
  729. FN_LOCAL_STRING(lp_username,szUsername)
  730. FN_LOCAL_STRING(lp_guestaccount,szGuestaccount)
  731. FN_LOCAL_STRING(lp_invalid_users,szInvalidUsers)
  732. FN_LOCAL_STRING(lp_valid_users,szValidUsers)
  733. FN_LOCAL_STRING(lp_admin_users,szAdminUsers)
  734. FN_LOCAL_STRING(lp_printcommand,szPrintcommand)
  735. FN_LOCAL_STRING(lp_lpqcommand,szLpqcommand)
  736. FN_LOCAL_STRING(lp_lprmcommand,szLprmcommand)
  737. FN_LOCAL_STRING(lp_lppausecommand,szLppausecommand)
  738. FN_LOCAL_STRING(lp_lpresumecommand,szLpresumecommand)
  739. FN_LOCAL_STRING(lp_printername,szPrintername)
  740. FN_LOCAL_STRING(lp_hostsallow,szHostsallow)
  741. FN_LOCAL_STRING(lp_hostsdeny,szHostsdeny)
  742. FN_LOCAL_STRING(lp_magicscript,szMagicScript)
  743. FN_LOCAL_STRING(lp_magicoutput,szMagicOutput)
  744. FN_LOCAL_STRING(lp_comment,comment)
  745. FN_LOCAL_STRING(lp_force_user,force_user)
  746. FN_LOCAL_STRING(lp_force_group,force_group)
  747. FN_LOCAL_STRING(lp_readlist,readlist)
  748. FN_LOCAL_STRING(lp_writelist,writelist)
  749. FN_LOCAL_STRING(lp_volume,volume)
  750. FN_LOCAL_STRING(lp_mangled_map,szMangledMap)
  751.  
  752. FN_LOCAL_BOOL(lp_alternate_permissions,bAlternatePerm)
  753. FN_LOCAL_BOOL(lp_revalidate,bRevalidate)
  754. FN_LOCAL_BOOL(lp_casesensitive,bCaseSensitive)
  755. FN_LOCAL_BOOL(lp_preservecase,bCasePreserve)
  756. FN_LOCAL_BOOL(lp_shortpreservecase,bShortCasePreserve)
  757. FN_LOCAL_BOOL(lp_casemangle,bCaseMangle)
  758. FN_LOCAL_BOOL(lp_status,status)
  759. FN_LOCAL_BOOL(lp_hide_dot_files,bHideDotFiles)
  760. FN_LOCAL_BOOL(lp_browseable,bBrowseable)
  761. FN_LOCAL_BOOL(lp_readonly,bRead_only)
  762. FN_LOCAL_BOOL(lp_no_set_dir,bNo_set_dir)
  763. FN_LOCAL_BOOL(lp_guest_ok,bGuest_ok)
  764. FN_LOCAL_BOOL(lp_guest_only,bGuest_only)
  765. FN_LOCAL_BOOL(lp_print_ok,bPrint_ok)
  766. FN_LOCAL_BOOL(lp_postscript,bPostscript)
  767. FN_LOCAL_BOOL(lp_map_hidden,bMap_hidden)
  768. FN_LOCAL_BOOL(lp_map_archive,bMap_archive)
  769. FN_LOCAL_BOOL(lp_locking,bLocking)
  770. FN_LOCAL_BOOL(lp_strict_locking,bStrictLocking)
  771. FN_LOCAL_BOOL(lp_share_modes,bShareModes)
  772. FN_LOCAL_BOOL(lp_onlyuser,bOnlyUser)
  773. FN_LOCAL_BOOL(lp_manglednames,bMangledNames)
  774. FN_LOCAL_BOOL(lp_widelinks,bWidelinks)
  775. FN_LOCAL_BOOL(lp_syncalways,bSyncAlways)
  776. FN_LOCAL_BOOL(lp_map_system,bMap_system)
  777.  
  778. FN_LOCAL_INTEGER(lp_create_mode,iCreate_mode)
  779. FN_LOCAL_INTEGER(lp_max_connections,iMaxConnections)
  780. FN_LOCAL_INTEGER(lp_defaultcase,iDefaultCase)
  781. FN_LOCAL_INTEGER(lp_minprintspace,iMinPrintSpace)
  782.  
  783. FN_LOCAL_CHAR(lp_magicchar,magic_char)
  784.  
  785.  
  786.  
  787. /* local prototypes */
  788. static int    strwicmp( char *psz1, char *psz2 );
  789. static int    map_parameter( char *pszParmName);
  790. static BOOL   set_boolean( BOOL *pb, char *pszParmValue );
  791. static int    getservicebyname(char *pszServiceName, service *pserviceDest);
  792. static void   copy_service( service *pserviceDest, 
  793.                             service *pserviceSource,
  794.                             BOOL *pcopymapDest );
  795. static BOOL   service_ok(int iService);
  796. static BOOL   do_parameter(char *pszParmName, char *pszParmValue);
  797. static BOOL   do_section(char *pszSectionName);
  798. static void   dump_globals(void);
  799. static void   dump_a_service(service *pService);
  800. static void init_copymap(service *pservice);
  801.  
  802.  
  803. /***************************************************************************
  804. initialise a service to the defaults
  805. ***************************************************************************/
  806. static void init_service(service *pservice)
  807. {
  808.   bzero((char *)pservice,sizeof(service));
  809.   copy_service(pservice,&sDefault,NULL);
  810. }
  811.  
  812.  
  813. /***************************************************************************
  814. free the dynamically allocated parts of a service struct
  815. ***************************************************************************/
  816. static void free_service(service *pservice)
  817. {
  818.   int i;
  819.   if (!pservice)
  820.      return;
  821.  
  822.   for (i=0;parm_table[i].label;i++)
  823.     if (parm_table[i].type == P_STRING && parm_table[i].class == P_LOCAL)
  824.       string_free((char **)(((char *)pservice) + PTR_DIFF(parm_table[i].ptr,&sDefault)));
  825. }
  826.  
  827. /***************************************************************************
  828. add a new service to the services array initialising it with the given 
  829. service
  830. ***************************************************************************/
  831. static int add_a_service(service *pservice, char *name)
  832. {
  833.   int i;
  834.   service tservice;
  835.   int num_to_alloc = iNumServices+1;
  836.  
  837.   tservice = *pservice;
  838.  
  839.   /* it might already exist */
  840.   if (name) 
  841.     {
  842.       i = getservicebyname(name,NULL);
  843.       if (i >= 0)
  844.     return(i);
  845.     }
  846.  
  847.   /* find an invalid one */
  848.   for (i=0;i<iNumServices;i++)
  849.     if (!pSERVICE(i)->valid)
  850.       break;
  851.  
  852.   /* if not, then create one */
  853.   if (i == iNumServices)
  854.     {
  855.       ServicePtrs = (service **)Realloc(ServicePtrs,sizeof(service *)*num_to_alloc);
  856.       if (ServicePtrs)
  857.     pSERVICE(iNumServices) = (service *)malloc(sizeof(service));
  858.  
  859.       if (!ServicePtrs || !pSERVICE(iNumServices))
  860.     return(-1);
  861.  
  862.       iNumServices++;
  863.     }
  864.   else
  865.     free_service(pSERVICE(i));
  866.  
  867.   pSERVICE(i)->valid = True;
  868.  
  869.   init_service(pSERVICE(i));
  870.   copy_service(pSERVICE(i),&tservice,NULL);
  871.   if (name)
  872.     string_set(&iSERVICE(i).szService,name);  
  873.  
  874.   return(i);
  875. }
  876.  
  877. /***************************************************************************
  878. add a new home service, with the specified home directory, defaults coming 
  879. from service ifrom
  880. ***************************************************************************/
  881. BOOL lp_add_home(char *pszHomename, int iDefaultService, char *pszHomedir)
  882. {
  883.   int i = add_a_service(pSERVICE(iDefaultService),pszHomename);
  884.  
  885.   if (i < 0)
  886.     return(False);
  887.  
  888.   if (!(*(iSERVICE(i).szPath)) || strequal(iSERVICE(i).szPath,lp_pathname(-1)))
  889.     string_set(&iSERVICE(i).szPath,pszHomedir);
  890.   if (!(*(iSERVICE(i).comment)))
  891.     {
  892.       pstring comment;
  893.       sprintf(comment,"Home directory of %s",pszHomename);
  894.       string_set(&iSERVICE(i).comment,comment);
  895.     }
  896.   iSERVICE(i).bAvailable = sDefault.bAvailable;
  897.   iSERVICE(i).bBrowseable = sDefault.bBrowseable;
  898.  
  899.   DEBUG(3,("adding home directory %s at %s\n", pszHomename, pszHomedir));
  900.  
  901.   return(True);
  902. }
  903.  
  904. /***************************************************************************
  905. add a new service, based on an old one
  906. ***************************************************************************/
  907. int lp_add_service(char *pszService, int iDefaultService)
  908. {
  909.   return(add_a_service(pSERVICE(iDefaultService),pszService));
  910. }
  911.  
  912.  
  913. /***************************************************************************
  914. add the IPC service
  915. ***************************************************************************/
  916. static BOOL lp_add_ipc(void)
  917. {
  918.   pstring comment;
  919.   int i = add_a_service(&sDefault,"IPC$");
  920.  
  921.   if (i < 0)
  922.     return(False);
  923.  
  924.   sprintf(comment,"IPC Service (%s)",lp_serverstring());
  925.  
  926.   string_set(&iSERVICE(i).szPath,"/tmp");
  927.   string_set(&iSERVICE(i).szUsername,"");
  928.   string_set(&iSERVICE(i).comment,comment);
  929.   iSERVICE(i).status = False;
  930.   iSERVICE(i).iMaxConnections = 0;
  931.   iSERVICE(i).bAvailable = True;
  932.   iSERVICE(i).bRead_only = True;
  933.   iSERVICE(i).bGuest_only = False;
  934.   iSERVICE(i).bGuest_ok = True;
  935.   iSERVICE(i).bPrint_ok = False;
  936.   iSERVICE(i).bBrowseable = sDefault.bBrowseable;
  937.  
  938.   DEBUG(3,("adding IPC service\n"));
  939.  
  940.   return(True);
  941. }
  942.  
  943.  
  944. /***************************************************************************
  945. add a new printer service, with defaults coming from service iFrom
  946. ***************************************************************************/
  947. BOOL lp_add_printer(char *pszPrintername, int iDefaultService)
  948. {
  949.   char *comment = "From Printcap";
  950.   int i = add_a_service(pSERVICE(iDefaultService),pszPrintername);
  951.   
  952.   if (i < 0)
  953.     return(False);
  954.   
  955.   /* note that we do NOT default the availability flag to True - */
  956.   /* we take it from the default service passed. This allows all */
  957.   /* dynamic printers to be disabled by disabling the [printers] */
  958.   /* entry (if/when the 'available' keyword is implemented!).    */
  959.   
  960.   /* the printer name is set to the service name. */
  961.   string_set(&iSERVICE(i).szPrintername,pszPrintername);
  962.   string_set(&iSERVICE(i).comment,comment);
  963.   iSERVICE(i).bBrowseable = sDefault.bBrowseable;
  964.   
  965.   DEBUG(3,("adding printer service %s\n",pszPrintername));
  966.   
  967.   return(True);
  968. }
  969.  
  970.  
  971. /***************************************************************************
  972. Do a case-insensitive, whitespace-ignoring string compare.
  973. ***************************************************************************/
  974. static int strwicmp(char *psz1, char *psz2)
  975. {
  976.    /* if BOTH strings are NULL, return TRUE, if ONE is NULL return */
  977.    /* appropriate value. */
  978.    if (psz1 == psz2)
  979.       return (0);
  980.    else
  981.       if (psz1 == NULL)
  982.          return (-1);
  983.       else
  984.           if (psz2 == NULL)
  985.               return (1);
  986.  
  987.    /* sync the strings on first non-whitespace */
  988.    while (1)
  989.    {
  990.       while (isspace(*psz1))
  991.          psz1++;
  992.       while (isspace(*psz2))
  993.          psz2++;
  994.       if (toupper(*psz1) != toupper(*psz2) || *psz1 == '\0' || *psz2 == '\0')
  995.          break;
  996.       psz1++;
  997.       psz2++;
  998.    }
  999.    return (*psz1 - *psz2);
  1000. }
  1001.  
  1002. /***************************************************************************
  1003. Map a parameter's string representation to something we can use. 
  1004. Returns False if the parameter string is not recognised, else TRUE.
  1005. ***************************************************************************/
  1006. static int map_parameter(char *pszParmName)
  1007. {
  1008.    int iIndex;
  1009.  
  1010.    if (*pszParmName == '-')
  1011.      return(-1);
  1012.  
  1013.    for (iIndex = 0; parm_table[iIndex].label; iIndex++) 
  1014.       if (strwicmp(parm_table[iIndex].label, pszParmName) == 0)
  1015.          return(iIndex);
  1016.  
  1017.    DEBUG(0,( "Unknown parameter encountered: \"%s\"\n", pszParmName));
  1018.    return(-1);
  1019. }
  1020.  
  1021.  
  1022. /***************************************************************************
  1023. Set a boolean variable from the text value stored in the passed string.
  1024. Returns True in success, False if the passed string does not correctly 
  1025. represent a boolean.
  1026. ***************************************************************************/
  1027. static BOOL set_boolean(BOOL *pb, char *pszParmValue)
  1028. {
  1029.    BOOL bRetval;
  1030.  
  1031.    bRetval = True;
  1032.    if (strwicmp(pszParmValue, "yes") == 0 ||
  1033.        strwicmp(pszParmValue, "true") == 0 ||
  1034.        strwicmp(pszParmValue, "1") == 0)
  1035.       *pb = True;
  1036.    else
  1037.       if (strwicmp(pszParmValue, "no") == 0 ||
  1038.           strwicmp(pszParmValue, "False") == 0 ||
  1039.           strwicmp(pszParmValue, "0") == 0)
  1040.          *pb = False;
  1041.       else
  1042.       {
  1043.          DEBUG(0,( "Badly formed boolean in configuration file: \"%s\".\n",
  1044.                pszParmValue));
  1045.          bRetval = False;
  1046.       }
  1047.    return (bRetval);
  1048. }
  1049.  
  1050. /***************************************************************************
  1051. Find a service by name. Otherwise works like get_service.
  1052. ***************************************************************************/
  1053. static int getservicebyname(char *pszServiceName, service *pserviceDest)
  1054. {
  1055.    int iService;
  1056.  
  1057.    for (iService = iNumServices - 1; iService >= 0; iService--)
  1058.       if (VALID(iService) &&
  1059.       strwicmp(iSERVICE(iService).szService, pszServiceName) == 0) 
  1060.       {
  1061.          if (pserviceDest != NULL)
  1062.        copy_service(pserviceDest, pSERVICE(iService), NULL);
  1063.          break;
  1064.       }
  1065.  
  1066.    return (iService);
  1067. }
  1068.  
  1069.  
  1070.  
  1071. /***************************************************************************
  1072. Copy a service structure to another
  1073.  
  1074. If pcopymapDest is NULL then copy all fields
  1075. ***************************************************************************/
  1076. static void copy_service(service *pserviceDest, 
  1077.                          service *pserviceSource,
  1078.                          BOOL *pcopymapDest)
  1079. {
  1080.   int i;
  1081.   BOOL bcopyall = (pcopymapDest == NULL);
  1082.  
  1083.   for (i=0;parm_table[i].label;i++)
  1084.     if (parm_table[i].ptr && parm_table[i].class == P_LOCAL && 
  1085.     (bcopyall || pcopymapDest[i]))
  1086.       {
  1087.     void *def_ptr = parm_table[i].ptr;
  1088.     void *src_ptr = 
  1089.       ((char *)pserviceSource) + PTR_DIFF(def_ptr,&sDefault);
  1090.     void *dest_ptr = 
  1091.       ((char *)pserviceDest) + PTR_DIFF(def_ptr,&sDefault);
  1092.  
  1093.     switch (parm_table[i].type)
  1094.       {
  1095.       case P_BOOL:
  1096.       case P_BOOLREV:
  1097.         *(BOOL *)dest_ptr = *(BOOL *)src_ptr;
  1098.         break;
  1099.  
  1100.       case P_INTEGER:
  1101.       case P_OCTAL:
  1102.         *(int *)dest_ptr = *(int *)src_ptr;
  1103.         break;
  1104.  
  1105.       case P_CHAR:
  1106.         *(char *)dest_ptr = *(char *)src_ptr;
  1107.         break;
  1108.  
  1109.       case P_STRING:
  1110.         string_set(dest_ptr,*(char **)src_ptr);
  1111.         break;
  1112.       default:
  1113.         break;
  1114.       }
  1115.       }
  1116.  
  1117.   if (bcopyall)
  1118.     {
  1119.       init_copymap(pserviceDest);
  1120.       if (pserviceSource->copymap)
  1121.     memcpy((void *)pserviceDest->copymap,
  1122.            (void *)pserviceSource->copymap,sizeof(BOOL)*NUMPARAMETERS);
  1123.     }
  1124. }
  1125.  
  1126. /***************************************************************************
  1127. Check a service for consistency. Return False if the service is in any way
  1128. incomplete or faulty, else True.
  1129. ***************************************************************************/
  1130. static BOOL service_ok(int iService)
  1131. {
  1132.    BOOL bRetval;
  1133.  
  1134.    bRetval = True;
  1135.    if (iSERVICE(iService).szService[0] == '\0')
  1136.    {
  1137.       DEBUG(0,( "The following message indicates an internal error:\n"));
  1138.       DEBUG(0,( "No service name in service entry.\n"));
  1139.       bRetval = False;
  1140.    }
  1141.  
  1142.    /* The [printers] entry MUST be printable. I'm all for flexibility, but */
  1143.    /* I can't see why you'd want a non-printable printer service...        */
  1144.    if (strwicmp(iSERVICE(iService).szService,PRINTERS_NAME) == 0)
  1145.       if (!iSERVICE(iService).bPrint_ok)
  1146.       {
  1147.          DEBUG(0,( "WARNING: [%s] service MUST be printable!\n",
  1148.                iSERVICE(iService).szService));
  1149.      iSERVICE(iService).bPrint_ok = True;
  1150.       }
  1151.  
  1152.    if (iSERVICE(iService).szPath[0] == '\0' &&
  1153.        strwicmp(iSERVICE(iService).szService,HOMES_NAME) != 0)
  1154.    {
  1155.       DEBUG(0,("No path in service %s - using /tmp\n",iSERVICE(iService).szService));
  1156.       string_set(&iSERVICE(iService).szPath,"/tmp");      
  1157.    }
  1158.  
  1159.    /* If a service is flagged unavailable, log the fact at level 0. */
  1160.    if (!iSERVICE(iService).bAvailable) 
  1161.       DEBUG(1,( "NOTE: Service %s is flagged unavailable.\n",
  1162.             iSERVICE(iService).szService));
  1163.  
  1164.    return (bRetval);
  1165. }
  1166.  
  1167. static struct file_lists {
  1168.   struct file_lists *next;
  1169.   char *name;
  1170.   time_t modtime;
  1171. } *file_lists = NULL;
  1172.  
  1173. /*******************************************************************
  1174. keep a linked list of all config files so we know when one has changed 
  1175. it's date and needs to be reloaded
  1176. ********************************************************************/
  1177. static void add_to_file_list(char *fname)
  1178. {
  1179.   struct file_lists *f=file_lists;
  1180.  
  1181.   while (f) {
  1182.     if (f->name && !strcmp(f->name,fname)) break;
  1183.     f = f->next;
  1184.   }
  1185.  
  1186.   if (!f) {
  1187.     f = (struct file_lists *)malloc(sizeof(file_lists[0]));
  1188.     if (!f) return;
  1189.     f->next = file_lists;
  1190.     f->name = strdup(fname);
  1191.     if (!f->name) {
  1192.       free(f);
  1193.       return;
  1194.     }
  1195.     file_lists = f;
  1196.   }
  1197.  
  1198.   {
  1199.     pstring n2;
  1200.     strcpy(n2,fname);
  1201.     standard_sub_basic(n2);
  1202.     f->modtime = file_modtime(n2);
  1203.   }
  1204.  
  1205. }
  1206.  
  1207. /*******************************************************************
  1208. check if a config file has changed date
  1209. ********************************************************************/
  1210. BOOL lp_file_list_changed(void)
  1211. {
  1212.   struct file_lists *f = file_lists;
  1213.   while (f) {
  1214.     pstring n2;
  1215.     strcpy(n2,f->name);
  1216.     standard_sub_basic(n2);
  1217.     if (f->modtime != file_modtime(n2)) return(True);
  1218.     f = f->next;   
  1219.   }
  1220.   return(False);
  1221. }
  1222.  
  1223. #ifdef KANJI
  1224. /***************************************************************************
  1225.   handle the interpretation of the coding system parameter
  1226.   *************************************************************************/
  1227. static BOOL handle_coding_system(char *pszParmValue,int *val)
  1228. {
  1229.   *val = interpret_coding_system(pszParmValue,*val);
  1230.   return(True);
  1231. }
  1232. #endif /* KANJI */
  1233.  
  1234. /***************************************************************************
  1235. handle the interpretation of the character set system parameter
  1236. ***************************************************************************/
  1237. static BOOL handle_character_set(char *pszParmValue,int *val)
  1238. {
  1239.   string_set(&Globals.szCharacterSet,pszParmValue);
  1240.   *val = interpret_character_set(pszParmValue,*val);
  1241.   return(True);
  1242. }
  1243.  
  1244.  
  1245. /***************************************************************************
  1246. handle the interpretation of the protocol parameter
  1247. ***************************************************************************/
  1248. static BOOL handle_protocol(char *pszParmValue,int *val)
  1249. {
  1250.   *val = interpret_protocol(pszParmValue,*val);
  1251.   return(True);
  1252. }
  1253.  
  1254. /***************************************************************************
  1255. handle the interpretation of the security parameter
  1256. ***************************************************************************/
  1257. static BOOL handle_security(char *pszParmValue,int *val)
  1258. {
  1259.   *val = interpret_security(pszParmValue,*val);
  1260.   return(True);
  1261. }
  1262.  
  1263. /***************************************************************************
  1264. handle the interpretation of the default case
  1265. ***************************************************************************/
  1266. static BOOL handle_case(char *pszParmValue,int *val)
  1267. {
  1268.   if (strequal(pszParmValue,"LOWER"))
  1269.     *val = CASE_LOWER;
  1270.   else if (strequal(pszParmValue,"UPPER"))
  1271.     *val = CASE_UPPER;
  1272.   return(True);
  1273. }
  1274.  
  1275. /***************************************************************************
  1276. handle the interpretation of the printing system
  1277. ***************************************************************************/
  1278. static BOOL handle_printing(char *pszParmValue,int *val)
  1279. {
  1280.   if (strequal(pszParmValue,"sysv"))
  1281.     *val = PRINT_SYSV;
  1282.   else if (strequal(pszParmValue,"aix"))
  1283.     *val = PRINT_AIX;
  1284.   else if (strequal(pszParmValue,"hpux"))
  1285.     *val = PRINT_HPUX;
  1286.   else if (strequal(pszParmValue,"bsd"))
  1287.     *val = PRINT_BSD;
  1288.   else if (strequal(pszParmValue,"qnx"))
  1289.     *val = PRINT_QNX;
  1290.   return(True);
  1291. }
  1292.  
  1293. /***************************************************************************
  1294. handle the valid chars lines
  1295. ***************************************************************************/
  1296. static BOOL handle_valid_chars(char *pszParmValue,char **ptr)
  1297.   string_set(ptr,pszParmValue);
  1298.  
  1299.   add_char_string(pszParmValue);
  1300.   return(True);
  1301. }
  1302.  
  1303.  
  1304. /***************************************************************************
  1305. handle the include operation
  1306. ***************************************************************************/
  1307. static BOOL handle_include(char *pszParmValue,char **ptr)
  1308.   pstring fname;
  1309.   strcpy(fname,pszParmValue);
  1310.  
  1311.   add_to_file_list(fname);
  1312.  
  1313.   standard_sub_basic(fname);
  1314.  
  1315.   string_set(ptr,fname);
  1316.  
  1317.   if (file_exist(fname,NULL))
  1318.     return(pm_process(fname, do_section, do_parameter));      
  1319.  
  1320.   DEBUG(2,("Can't find include file %s\n",fname));
  1321.  
  1322.   return(False);
  1323. }
  1324.  
  1325.  
  1326. /***************************************************************************
  1327. handle the interpretation of the copy parameter
  1328. ***************************************************************************/
  1329. static BOOL handle_copy(char *pszParmValue,char **ptr)
  1330. {
  1331.    BOOL bRetval;
  1332.    int iTemp;
  1333.    service serviceTemp;
  1334.  
  1335.    string_set(ptr,pszParmValue);
  1336.  
  1337.    init_service(&serviceTemp);
  1338.  
  1339.    bRetval = False;
  1340.    
  1341.    DEBUG(3,("Copying service from service %s\n",pszParmValue));
  1342.  
  1343.    if ((iTemp = getservicebyname(pszParmValue, &serviceTemp)) >= 0)
  1344.      {
  1345.        if (iTemp == iServiceIndex)
  1346.      {
  1347.        DEBUG(0,("Can't copy service %s - unable to copy self!\n",
  1348.             pszParmValue));
  1349.      }
  1350.        else
  1351.      {
  1352.        copy_service(pSERVICE(iServiceIndex), 
  1353.             &serviceTemp,
  1354.             iSERVICE(iServiceIndex).copymap);
  1355.        bRetval = True;
  1356.      }
  1357.      }
  1358.    else
  1359.      {
  1360.        DEBUG(0,( "Unable to copy service - source not found: %s\n",
  1361.         pszParmValue));
  1362.        bRetval = False;
  1363.      }
  1364.  
  1365.    free_service(&serviceTemp);
  1366.    return (bRetval);
  1367. }
  1368.  
  1369.  
  1370. /***************************************************************************
  1371. initialise a copymap
  1372. ***************************************************************************/
  1373. static void init_copymap(service *pservice)
  1374. {
  1375.   int i;
  1376.   if (pservice->copymap) free(pservice->copymap);
  1377.   pservice->copymap = (BOOL *)malloc(sizeof(BOOL)*NUMPARAMETERS);
  1378.   if (!pservice->copymap)
  1379.     DEBUG(0,("Couldn't allocate copymap!! (size %d)\n",NUMPARAMETERS));
  1380.  
  1381.   for (i=0;i<NUMPARAMETERS;i++)
  1382.     pservice->copymap[i] = True;
  1383. }
  1384.  
  1385.  
  1386. /***************************************************************************
  1387. Process a parameter.
  1388. ***************************************************************************/
  1389. static BOOL do_parameter(char *pszParmName, char *pszParmValue)
  1390. {
  1391.    int parmnum;
  1392.    void *parm_ptr=NULL; /* where we are going to store the result */
  1393.    void *def_ptr=NULL;
  1394.  
  1395.    if (!bInGlobalSection && bGlobalOnly) return(True);
  1396.  
  1397.    DEBUG(3,("doing parameter %s = %s\n",pszParmName,pszParmValue));
  1398.    
  1399.    parmnum = map_parameter(pszParmName);
  1400.  
  1401.    if (parmnum < 0)
  1402.      {
  1403.        DEBUG(0,( "Ignoring unknown parameter \"%s\"\n", pszParmName));
  1404.        return(True);
  1405.      }
  1406.  
  1407.    def_ptr = parm_table[parmnum].ptr;
  1408.  
  1409.    /* we might point at a service, the default service or a global */
  1410.    if (bInGlobalSection)
  1411.      parm_ptr = def_ptr;
  1412.    else
  1413.      {
  1414.        if (parm_table[parmnum].class == P_GLOBAL)
  1415.      {
  1416.        DEBUG(0,( "Global parameter %s found in service section!\n",pszParmName));
  1417.        return(True);
  1418.      }
  1419.        parm_ptr = ((char *)pSERVICE(iServiceIndex)) + PTR_DIFF(def_ptr,&sDefault);
  1420.      }
  1421.  
  1422.    if (!bInGlobalSection)
  1423.      {
  1424.        int i;
  1425.        if (!iSERVICE(iServiceIndex).copymap)
  1426.      init_copymap(pSERVICE(iServiceIndex));
  1427.        
  1428.        /* this handles the aliases - set the copymap for other entries with
  1429.       the same data pointer */
  1430.        for (i=0;parm_table[i].label;i++)
  1431.      if (parm_table[i].ptr == parm_table[parmnum].ptr)
  1432.        iSERVICE(iServiceIndex).copymap[i] = False;
  1433.      }
  1434.  
  1435.    /* if it is a special case then go ahead */
  1436.    if (parm_table[parmnum].special)
  1437.      {
  1438.        parm_table[parmnum].special(pszParmValue,parm_ptr);
  1439.        return(True);
  1440.      }
  1441.  
  1442.    /* now switch on the type of variable it is */
  1443.    switch (parm_table[parmnum].type)
  1444.      {
  1445.      case P_BOOL:
  1446.        set_boolean(parm_ptr,pszParmValue);
  1447.        break;
  1448.  
  1449.      case P_BOOLREV:
  1450.        set_boolean(parm_ptr,pszParmValue);
  1451.        *(BOOL *)parm_ptr = ! *(BOOL *)parm_ptr;
  1452.        break;
  1453.  
  1454.      case P_INTEGER:
  1455.        *(int *)parm_ptr = atoi(pszParmValue);
  1456.        break;
  1457.  
  1458.      case P_CHAR:
  1459.        *(char *)parm_ptr = *pszParmValue;
  1460.        break;
  1461.  
  1462.      case P_OCTAL:
  1463.        sscanf(pszParmValue,"%o",(int *)parm_ptr);
  1464.        break;
  1465.  
  1466.      case P_STRING:
  1467.        string_set(parm_ptr,pszParmValue);
  1468.        break;
  1469.  
  1470.      case P_GSTRING:
  1471.        strcpy((char *)parm_ptr,pszParmValue);
  1472.        break;
  1473.      }
  1474.  
  1475.    return(True);
  1476. }
  1477.  
  1478. /***************************************************************************
  1479. print a parameter of the specified type
  1480. ***************************************************************************/
  1481. static void print_parameter(parm_type type,void *ptr)
  1482. {
  1483.   switch (type)
  1484.     {
  1485.     case P_BOOL:
  1486.       printf("%s",BOOLSTR(*(BOOL *)ptr));
  1487.       break;
  1488.       
  1489.     case P_BOOLREV:
  1490.       printf("%s",BOOLSTR(! *(BOOL *)ptr));
  1491.       break;
  1492.       
  1493.     case P_INTEGER:
  1494.       printf("%d",*(int *)ptr);
  1495.       break;
  1496.       
  1497.     case P_CHAR:
  1498.       printf("%c",*(char *)ptr);
  1499.       break;
  1500.       
  1501.     case P_OCTAL:
  1502.       printf("0%o",*(int *)ptr);
  1503.       break;
  1504.       
  1505.     case P_GSTRING:
  1506.       if ((char *)ptr)
  1507.     printf("%s",(char *)ptr);
  1508.       break;
  1509.  
  1510.     case P_STRING:
  1511.       if (*(char **)ptr)
  1512.     printf("%s",*(char **)ptr);
  1513.       break;
  1514.     }
  1515. }
  1516.  
  1517.  
  1518. /***************************************************************************
  1519. check if two parameters are equal
  1520. ***************************************************************************/
  1521. static BOOL equal_parameter(parm_type type,void *ptr1,void *ptr2)
  1522. {
  1523.   switch (type)
  1524.     {
  1525.     case P_BOOL:
  1526.     case P_BOOLREV:
  1527.       return(*((BOOL *)ptr1) == *((BOOL *)ptr2));
  1528.  
  1529.     case P_INTEGER:
  1530.     case P_OCTAL:
  1531.       return(*((int *)ptr1) == *((int *)ptr2));
  1532.       
  1533.     case P_CHAR:
  1534.       return(*((char *)ptr1) == *((char *)ptr2));
  1535.  
  1536.     case P_GSTRING:
  1537.       {
  1538.     char *p1 = (char *)ptr1, *p2 = (char *)ptr2;
  1539.     if (p1 && !*p1) p1 = NULL;
  1540.     if (p2 && !*p2) p2 = NULL;
  1541.     return(p1==p2 || strequal(p1,p2));
  1542.       }
  1543.     case P_STRING:
  1544.       {
  1545.     char *p1 = *(char **)ptr1, *p2 = *(char **)ptr2;
  1546.     if (p1 && !*p1) p1 = NULL;
  1547.     if (p2 && !*p2) p2 = NULL;
  1548.     return(p1==p2 || strequal(p1,p2));
  1549.       }
  1550.     }
  1551.   return(False);
  1552. }
  1553.  
  1554. /***************************************************************************
  1555. Process a new section (service). At this stage all sections are services.
  1556. Later we'll have special sections that permit server parameters to be set.
  1557. Returns True on success, False on failure.
  1558. ***************************************************************************/
  1559. static BOOL do_section(char *pszSectionName)
  1560. {
  1561.    BOOL bRetval;
  1562.    BOOL isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) || 
  1563.             (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
  1564.    bRetval = False;
  1565.  
  1566.    /* if we were in a global section then do the local inits */
  1567.    if (bInGlobalSection && !isglobal)
  1568.      init_locals();
  1569.  
  1570.    /* if we've just struck a global section, note the fact. */
  1571.    bInGlobalSection = isglobal;   
  1572.  
  1573.    /* check for multiple global sections */
  1574.    if (bInGlobalSection)
  1575.    {
  1576.      DEBUG(3,( "Processing section \"[%s]\"\n", pszSectionName));
  1577.      return(True);
  1578.    }
  1579.  
  1580.    if (!bInGlobalSection && bGlobalOnly) return(True);
  1581.  
  1582.    /* if we have a current service, tidy it up before moving on */
  1583.    bRetval = True;
  1584.  
  1585.    if (iServiceIndex >= 0)
  1586.      bRetval = service_ok(iServiceIndex);
  1587.  
  1588.    /* if all is still well, move to the next record in the services array */
  1589.    if (bRetval)
  1590.      {
  1591.        /* We put this here to avoid an odd message order if messages are */
  1592.        /* issued by the post-processing of a previous section. */
  1593.        DEBUG(2,( "Processing section \"[%s]\"\n", pszSectionName));
  1594.  
  1595.        if ((iServiceIndex=add_a_service(&sDefault,pszSectionName)) < 0)
  1596.      {
  1597.        DEBUG(0,("Failed to add a new service\n"));
  1598.        return(False);
  1599.      }
  1600.      }
  1601.  
  1602.    return (bRetval);
  1603. }
  1604.  
  1605. /***************************************************************************
  1606. Display the contents of the global structure.
  1607. ***************************************************************************/
  1608. static void dump_globals(void)
  1609. {
  1610.   int i;
  1611.   printf("Global parameters:\n");
  1612.  
  1613.   for (i=0;parm_table[i].label;i++)
  1614.     if (parm_table[i].class == P_GLOBAL &&
  1615.     parm_table[i].ptr &&
  1616.     (i == 0 || (parm_table[i].ptr != parm_table[i-1].ptr)))
  1617.       {
  1618.     printf("\t%s: ",parm_table[i].label);
  1619.     print_parameter(parm_table[i].type,parm_table[i].ptr);
  1620.     printf("\n");
  1621.       }
  1622. }
  1623.  
  1624. /***************************************************************************
  1625. Display the contents of a single services record.
  1626. ***************************************************************************/
  1627. static void dump_a_service(service *pService)
  1628. {
  1629.   int i;
  1630.   if (pService == &sDefault)
  1631.     printf("\nDefault service parameters:\n");
  1632.   else
  1633.     printf("\nService parameters [%s]:\n",pService->szService);
  1634.  
  1635.   for (i=0;parm_table[i].label;i++)
  1636.     if (parm_table[i].class == P_LOCAL &&
  1637.     parm_table[i].ptr && 
  1638.     (*parm_table[i].label != '-') &&
  1639.     (i == 0 || (parm_table[i].ptr != parm_table[i-1].ptr)))
  1640.       {
  1641.     int pdiff = PTR_DIFF(parm_table[i].ptr,&sDefault);
  1642.  
  1643.     if (pService == &sDefault || !equal_parameter(parm_table[i].type,
  1644.                               ((char *)pService) + pdiff,
  1645.                               ((char *)&sDefault) + pdiff))
  1646.       {
  1647.         printf("\t%s: ",parm_table[i].label);
  1648.         print_parameter(parm_table[i].type,
  1649.                 ((char *)pService) + pdiff);
  1650.         printf("\n");
  1651.       }
  1652.       }
  1653. }
  1654.  
  1655. #if 0
  1656. /***************************************************************************
  1657. Display the contents of a single copy structure.
  1658. ***************************************************************************/
  1659. static void dump_copy_map(BOOL *pcopymap)
  1660. {
  1661.   int i;
  1662.   if (!pcopymap) return;
  1663.  
  1664.   printf("\n\tNon-Copied parameters:\n");
  1665.  
  1666.   for (i=0;parm_table[i].label;i++)
  1667.     if (parm_table[i].class == P_LOCAL &&
  1668.     parm_table[i].ptr && !pcopymap[i] &&
  1669.     (i == 0 || (parm_table[i].ptr != parm_table[i-1].ptr)))
  1670.       {
  1671.     printf("\t\t%s\n",parm_table[i].label);
  1672.       }
  1673. }
  1674. #endif
  1675.  
  1676. /***************************************************************************
  1677. Return TRUE if the passed service number is within range.
  1678. ***************************************************************************/
  1679. BOOL lp_snum_ok(int iService)
  1680. {
  1681.    return (LP_SNUM_OK(iService) && iSERVICE(iService).bAvailable);
  1682. }
  1683.  
  1684.  
  1685. /***************************************************************************
  1686. auto-load some homes and printer services
  1687. ***************************************************************************/
  1688. static void lp_add_auto_services(char *str)
  1689. {
  1690.   char *s;
  1691.   char *p;
  1692.   int homes = lp_servicenumber(HOMES_NAME);
  1693.   int printers = lp_servicenumber(PRINTERS_NAME);
  1694.  
  1695.   if (!str)
  1696.     return;
  1697.  
  1698.   s = strdup(str);
  1699.   if (!s) return;
  1700.  
  1701.   for (p=strtok(s,LIST_SEP);p;p=strtok(NULL,LIST_SEP))
  1702.     {
  1703.       char *home = get_home_dir(p);
  1704.  
  1705.       if (lp_servicenumber(p) >= 0) continue;
  1706.  
  1707.       if (home && homes >= 0)
  1708.     {
  1709.       lp_add_home(p,homes,home);
  1710.       continue;
  1711.     }
  1712.  
  1713.       if (printers >= 0 && pcap_printername_ok(p,NULL))
  1714.     lp_add_printer(p,printers);
  1715.     }
  1716.   free(s);
  1717. }
  1718.  
  1719. /***************************************************************************
  1720. auto-load one printer
  1721. ***************************************************************************/
  1722. static void lp_add_one_printer(char *name,char *comment)
  1723. {
  1724.   int printers = lp_servicenumber(PRINTERS_NAME);
  1725.   int i;
  1726.  
  1727.   if (lp_servicenumber(name) < 0)
  1728.     {
  1729.       lp_add_printer(name,printers);
  1730.       if ((i=lp_servicenumber(name)) >= 0)
  1731.     string_set(&iSERVICE(i).comment,comment);
  1732.     }      
  1733. }
  1734.  
  1735.  
  1736. /***************************************************************************
  1737. auto-load printer services
  1738. ***************************************************************************/
  1739. static void lp_add_all_printers(void)
  1740. {
  1741.   int printers = lp_servicenumber(PRINTERS_NAME);
  1742.  
  1743.   if (printers < 0) return;
  1744.  
  1745.   pcap_printer_fn(lp_add_one_printer);
  1746. }
  1747.  
  1748. /***************************************************************************
  1749. have we loaded a services file yet?
  1750. ***************************************************************************/
  1751. BOOL lp_loaded(void)
  1752. {
  1753.   return(bLoaded);
  1754. }
  1755.  
  1756. /***************************************************************************
  1757. unload unused services
  1758. ***************************************************************************/
  1759. void lp_killunused(BOOL (*snumused)(int ))
  1760. {
  1761.   int i;
  1762.   for (i=0;i<iNumServices;i++)
  1763.     if (VALID(i) && !snumused(i))
  1764.       {
  1765.     iSERVICE(i).valid = False;
  1766.     free_service(pSERVICE(i));
  1767.       }
  1768. }
  1769.  
  1770. /***************************************************************************
  1771. Load the services array from the services file. Return True on success, 
  1772. False on failure.
  1773. ***************************************************************************/
  1774. BOOL lp_load(char *pszFname,BOOL global_only)
  1775. {
  1776.   pstring n2;
  1777.   BOOL bRetval;
  1778.   
  1779.   add_to_file_list(pszFname);
  1780.  
  1781.   bRetval = False;
  1782.  
  1783.   bInGlobalSection = True;
  1784.   bGlobalOnly = global_only;
  1785.   
  1786.   init_globals();
  1787.   
  1788.   strcpy(n2,pszFname);
  1789.   standard_sub_basic(n2);
  1790.  
  1791.   /* We get sections first, so have to start 'behind' to make up */
  1792.   iServiceIndex = -1;
  1793.   bRetval = pm_process(n2, do_section, do_parameter);
  1794.   
  1795.   /* finish up the last section */
  1796.   DEBUG(3,("pm_process() returned %s\n", BOOLSTR(bRetval)));
  1797.   if (bRetval)
  1798.     if (iServiceIndex >= 0)
  1799.       bRetval = service_ok(iServiceIndex);       
  1800.  
  1801.   lp_add_auto_services(lp_auto_services());
  1802.   if (lp_load_printers())
  1803.     lp_add_all_printers();
  1804.  
  1805.   lp_add_ipc();
  1806.  
  1807.   bLoaded = True;
  1808.  
  1809.   return (bRetval);
  1810. }
  1811.  
  1812.  
  1813. /***************************************************************************
  1814. return the max number of services
  1815. ***************************************************************************/
  1816. int lp_numservices(void)
  1817. {
  1818.   return(iNumServices);
  1819. }
  1820.  
  1821. /***************************************************************************
  1822. Display the contents of the services array in human-readable form.
  1823. ***************************************************************************/
  1824. void lp_dump(void)
  1825. {
  1826.    int iService;
  1827.  
  1828.    dump_globals();
  1829.    
  1830.    dump_a_service(&sDefault);
  1831.  
  1832.    for (iService = 0; iService < iNumServices; iService++)
  1833.    {
  1834.      if (VALID(iService))
  1835.        {
  1836.      if (iSERVICE(iService).szService[0] == '\0')
  1837.        break;
  1838.      dump_a_service(pSERVICE(iService));
  1839.        }
  1840.    }
  1841. }
  1842.  
  1843. /***************************************************************************
  1844. Return the number of the service with the given name, or -1 if it doesn't
  1845. exist. Note that this is a DIFFERENT ANIMAL from the internal function
  1846. getservicebyname()! This works ONLY if all services have been loaded, and
  1847. does not copy the found service.
  1848. ***************************************************************************/
  1849. int lp_servicenumber(char *pszServiceName)
  1850. {
  1851.    int iService;
  1852.  
  1853.    for (iService = iNumServices - 1; iService >= 0; iService--)
  1854.       if (VALID(iService) &&
  1855.       strwicmp(iSERVICE(iService).szService, pszServiceName) == 0) 
  1856.          break;
  1857.  
  1858.    if (iService < 0)
  1859.      DEBUG(7,("lp_servicenumber: couldn't find %s\n",pszServiceName));
  1860.    
  1861.    return (iService);
  1862. }
  1863.  
  1864.  
  1865.  
  1866.  
  1867. /*******************************************************************
  1868.   get a workgroup - but map to standalone if '*'
  1869.   ******************************************************************/
  1870. char *my_workgroup(void)
  1871. {
  1872.   char *res = lp_workgroup();
  1873.   if (*res == '*') return("STANDALONE");
  1874.   return(res);
  1875. }
  1876.  
  1877. /*******************************************************************
  1878.   a useful volume label function
  1879.   ******************************************************************/
  1880. char *volume_label(int snum)
  1881. {
  1882.   char *ret = lp_volume(snum);
  1883.   if (!*ret) return(lp_servicename(snum));
  1884.   return(ret);
  1885. }
  1886.